#include "Mouse.h"
#include<graphics.h>
#include<easyx.h>
#include<iostream>
using namespace std;

Mouse::Mouse()
{
}

int Mouse::menujudge()// determine which button the mouse is pointing to
{
	if (point.y >= 79 && point.y <= 97)
	{
		if (point.x > 868 && point.x < 907)
		{
			return map_mode_low;
		}
		else if (point.x > 934 && point.x < 973)
		{
			return map_mode_high;
		}
	}
	else if (point.y >= 115 && point.y <= 138)
	{
		if (point.x>655&&point.x<785)
		{
			return map_rebuild;
		}
		else if (point.x > 868 && point.x < 985)
		{
			return map_erase;
		}
	}
	else if (point.y > 156 && point.y < 172)
	{
		if (point.x > 868 && point.x < 923)
		{
			return point_users;
		}
		else if (point.x > 945 && point.x < 997)
		{
			return point_done;
		}
	}
	else if (point.y > 197 && point.y < 217)
	{
		if(point.x>810) return replay;
	}
	return 2000;
}



bool Mouse::action()//Determine whether the left mouse button is double-click, and record the location of the double-click
{
	bool flag = 0;
	if (MouseHit())// check for mouse messages
	{
		msg = GetMouseMsg();// gets a mouse message.If not, wait
		if (msg.uMsg == WM_LBUTTONDBLCLK)// to determine whether the left mouse button is double-clicked
		{
			cout << msg.x << " " << msg.y << endl;
			point.x = msg.x; point.y = msg.y;//Get mouse coordinates
			flag = 1;
		}
	}
	FlushMouseMsgBuffer();// clear the mouse message buffer
	return flag;
}

int Mouse::mapjudge()// determine the coordinates of the small rectangle where the mouse is pointing to
{
	
	if (point.x <= 600)
	{
		int tmp_x = point.x - 120;//The x coordinate of the mouse in the coordinate system set by myself
		int tmp_y = point.y - 40; //The y coordinate of the mouse in the coordinate system set by myself
		int k = 20;
		int x = tmp_x / k + 1;// The x coordinate of the small rectangle where the mouse is pointing to
		int y = tmp_y / k + 1; //The y coordinate of the small rectangle where the mouse is pointing to
		int ans = x * 100 + y;// In order to be  easy to get the coordinates of the small rectangle where the mouse is located elsewhere 
		//cout << "hhehehehe" << endl;
		return ans;
	}
}




Mouse::~Mouse()
{
}
